package validators

import "github.com/runningwater/gohub/pkg/verifycode"

// ValidatePasswordConfirm 用于验证密码和确认密码是否一致
func ValidatePasswordConfirm(password, passwordConfirm string, errs map[string][]string) map[string][]string {
	if password != passwordConfirm {
		errs["password_confirm"] = append(errs["password_confirm"], "密码和确认密码不匹配")
	}
	return errs
}

// ValidateVerifyCode 用于验证验证码是否正确
// 该函数接受验证码的 key 和用户输入的答案
// 如果验证码不正确，则将错误信息添加到 errs 映射中
func ValidateVerifyCode(key, answer string, errs map[string][]string) map[string][]string {
	if ok := verifycode.NewVerifyCode().CheckAnswer(key, answer); !ok {
		errs["verify_code"] = append(errs["verify_code"], "验证码错误")
	}
	return errs
}
